home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDStopTrack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  4.3 KB  |  164 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDStopTrack - An XCMD to stop play at the end of a specific track.
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/10/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDStopTrack.c
  11.     link -sn Main=CDStopTrack -sn STDIO=CDStopTrack ∂
  12.          -sn INTENV=CDStopTrack -rt XFCN=42 ∂
  13.          -m CDStopTrack CDStopTrack.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. void    ExtractTrackNo(char *, short *);
  28. OSErr    AStop(short, short);
  29.  
  30. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  31.  
  32.  
  33. /************************************************************************
  34.  *
  35.  *  Function:        CDStopTrack
  36.  *
  37.  *  Purpose:        stop playing at the end of an audio track
  38.  *
  39.  *  Returns:        result of driver call to stop track
  40.  *                    normally 0, but could have parameter error or
  41.  *                    other error if non-existent track is specified
  42.  *
  43.  *  Side Effects:
  44.  *
  45.  *  Description:    We need one parameters. Get the ioRefNum that we got
  46.  *                    from previously calling CDOpen() via a famous
  47.  *                    global.  Get the track
  48.  *                    number.  Extract the track number and issue a stop.
  49.  *                    To play only one track, you issue a stop for that
  50.  *                    track, followed by a play for that track.
  51.  *
  52.  ************************************************************************/
  53. pascal void
  54. CDStopTrack(paramPtr)
  55.     XCmdBlockPtr    paramPtr;
  56. {
  57.     Str31    returnString;
  58.     OSErr    result;
  59.     short    trackNumber;
  60.     short    ioRefNum;
  61.     Handle    refHandle;
  62.     
  63.     /* Must be one parameter */
  64.     if ((paramPtr->paramCount) != 1)
  65.     {
  66.         /* Report error in parameters by returning -1 */
  67.         NumToStr(paramPtr, (long) -1, &returnString);
  68.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  69.         return;
  70.     }
  71.     
  72.     /* Get the global ioRefNum and convert it. */
  73.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  74.     ioRefNum = atoi(*(refHandle));
  75.     DisposHandle(refHandle);
  76.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  77.     
  78.     /* First param is track number.  Convert it to a pascal string */
  79.     ExtractTrackNo((char *)*(paramPtr->params[0]), &trackNumber);
  80.     
  81.     result = AStop(trackNumber, ioRefNum);
  82.     
  83.     /* Convert result to string & return it */
  84.     NumToStr(paramPtr, (long) result, &returnString);
  85.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  86. }
  87.  
  88.  
  89. /************************************************************************
  90.  *
  91.  *  Function:        ExtractTrackNo
  92.  *
  93.  *  Purpose:        Extract track number in BCD from PString
  94.  *
  95.  *  Returns:        nothing
  96.  *
  97.  *  Side Effects:    *track gets a new value
  98.  *
  99.  *  Description:    Extract track number in BCD from Cstring "name".
  100.  *                    "name" is always of the form "XX", where XX
  101.  *                    ranges from "1"  to "99"
  102.  *                    (You can't have more than 99 tracks on a compact disc.
  103.  *                    Bet you didn't know that, did you?  Right in the "Yellow
  104.  *                    Book" specification of compact disc encoding.)
  105.  *
  106.  ************************************************************************/
  107. void
  108. ExtractTrackNo(name, track)
  109. char        *name;
  110. short        *track;
  111. {
  112.     short    t;
  113.         
  114.     t = 0;
  115.     while (*name != 0)
  116.     {
  117.         t *= 16;
  118.         t += *name - '0';
  119.         name++;
  120.     }
  121.     
  122.     *track = t;    
  123. }
  124.  
  125. /************************************************************************
  126.  *
  127.  *  Function:        AStop
  128.  *
  129.  *  Purpose:        stop playing an audio track
  130.  *
  131.  *  Returns:        OSErr.  Probably either
  132.  *                        noErr        everything's hunky-dory!
  133.  *                        paramErr    you messed up the call somehow.
  134.  *
  135.  *  Side Effects:    stops play.
  136.  *
  137.  *  Description:    The track that you pass in is the LAST track that you
  138.  *                    want to have play.  This means that if you wanted to
  139.  *                    play only one track, you'd pass the same value to
  140.  *                    this routine and APlay() [q.v.]
  141.  *
  142.  *                    Note that this routine isn't called in this sample,
  143.  *                    but it's included for your enjoyment.
  144.  *
  145.  ************************************************************************/
  146. OSErr
  147. AStop(track, refNum)
  148. short    track;
  149. short    refNum;
  150. {
  151.     struct {
  152.         short    addrFormat;
  153.         long    address;
  154.     }    csParam;
  155.     
  156.     csParam.addrFormat = TRACKADDR;
  157.     csParam.address = track;
  158.     return (Control(refNum, ASTOP, &csParam));
  159. }
  160.  
  161.  
  162. /* C routines for HyperCard callbacks */
  163. #include <XCmdGlue.inc.c>
  164.